package com.example.personnel_management_system.controller;

import com.example.personnel_management_system.entity.Positions;
import com.example.personnel_management_system.service.IPositionsService;
import com.example.personnel_management_system.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("positions")
public class PositionsController {
    @Autowired
    private IPositionsService positionsService;
    @RequestMapping("addpositions")
    public Result<Void>addpositions(Positions positions){
        try {
            positionsService.insert(positions);
            return Result.success();
        }catch (Exception e){
            return Result.failure();
        }
    }
    @RequestMapping("update")
    public Result<Void>update(Positions positions){
        try {
            positionsService.update(positions);
            return Result.success();
        }catch (Exception e){
            return Result.failure();
        }
    }
    @RequestMapping("findByType")
    public Result<List<Positions>>findByType(String pCategory){
        return Result.success(positionsService.findByType(pCategory));
    }
    @RequestMapping("findall")
    public Result<List<Positions>>findall(){
        return Result.success(positionsService.findall());
    }
    @RequestMapping("findBypId")
    public Result<Positions>findBypId(Integer pID){
        return Result.success(positionsService.findBypId(pID));
    }
    @RequestMapping("findType")
    public Result<List<String>>findType(){
        return Result.success(positionsService.findType());
    }

}
